package com.climber.android.commonsdk.util.date;

import android.annotation.SuppressLint;

import java.text.ParseException;
import java.text.SimpleDateFormat;
import java.util.Locale;
import java.util.TimeZone;

/**
 * 日期时间类
 * yyyy-MM-dd
 * Created by Tony on 1/5/15.
 */
@SuppressLint("SimpleDateFormat")
public class Date extends BaseDate {
    public final static SimpleDateFormat FORMATTER_DATE = new SimpleDateFormat("yyyy-MM-dd");
    public final static SimpleDateFormat FORMATTER_DATE_CN = new SimpleDateFormat("yyyy年MM月dd日");

    public final static SimpleDateFormat FORMATTER_MONTH_DAY_CN = new SimpleDateFormat("MM月dd日");
    public final static SimpleDateFormat FORMATTER_MONTH_DAY = new SimpleDateFormat("MM-dd");

    public final static SimpleDateFormat FORMATTER_DATE_TIME_CN = new SimpleDateFormat("yyyy年MM月dd日 HH:mm:ss");
    public static final SimpleDateFormat FORMATTER_DATE_TIME = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");

    public final static SimpleDateFormat FORMATTER_HOUR_MINUTE = new SimpleDateFormat("HH:mm");

    public final static SimpleDateFormat FORMATTER_DAY_HOUR = new SimpleDateFormat("MM-dd HH:mm");
    public final static SimpleDateFormat FORMATTER_DAY_HOUR_CN = new SimpleDateFormat("MM月dd日 HH:mm");

    public final static SimpleDateFormat FORMAT_WEEK = new SimpleDateFormat("E", Locale.CHINA);

    //UTC timestamp,so we need TimeZone is China
    public final static SimpleDateFormat FORMATTER_UTC = new SimpleDateFormat("yyyy-MM-dd'T'HH:mm:ss'Z'");

    static {
        FORMATTER_UTC.setTimeZone(TimeZone.getTimeZone("UTC"));
    }

    /**
     * 新建一个日期类
     *
     * @return
     */
    public static Date newInstance() {
        // now to yyyy-MM-dd
        String nowDate = FORMATTER_DATE.format(new java.util.Date());
        try {
            return new Date(FORMATTER_DATE.parse(nowDate));
        } catch (ParseException e) {
            e.printStackTrace();
        }
        return new Date(System.currentTimeMillis());
    }

    public Date(long readLong) {
        super(readLong);
    }

    public Date(java.util.Date date) {
        super(date.getTime());
    }
}
